package top.cardone.api.v1.configuration.errorInfo

import org.apache.commons.lang3.StringUtils
import top.cardone.configuration.service.ErrorInfoService
import top.cardone.context.ApplicationContextHolder
import top.cardone.core.CodeException

class c0001 implements java.io.Serializable {
    def input(input) {
        def newInput = [:]


        newInput
    }

    def validation(input) {
//      if (StringUtils.isBlank(input?.errorInfoCode)) {
//          throw new CodeException("errorInfoCode required", "ErrorInfo编号必填")
//      }
//
//      if (StringUtils.length(input?.errorInfoCode) < 4) {
//          throw new CodeException("errorInfoCode minlength", "ErrorInfo编号需{0}个字符以上", 4)
//      }
//
//      if (StringUtils.length(input?.errorInfoCode) > 255) {
//          throw new CodeException("errorInfoCode maxlength", "ErrorInfo编号需小于{0}个字符", 255)
//      }
//
//      if (StringUtils.isBlank(input?.name)) {
//          throw new CodeException("name required", "ErrorInfo名称必填")
//      }
//
//      if (StringUtils.length(input?.name) < 4) {
//          throw new CodeException("name minlength", "ErrorInfo名称需{0}个字符以上", 4)
//      }
//
//      if (StringUtils.length(input?.name) > 255) {
//          throw new CodeException("name maxlength", "ErrorInfo名称需小于{0}个字符", 255)
//      }
		
		def readOne = ['errorInfoCode': input.errorInfoCode]

		def count = ApplicationContextHolder.getBean(ErrorInfoService.class).readOne(Integer.class, readOne)

		if (count > 0) {
			throw new CodeException("errorInfoCode already exists", "ErrorInfo编号已经存在")
		}
    }

    def func(input) {
		ApplicationContextHolder.getBean(ErrorInfoService.class).insertByNotExistsCache(input)
    }

    def output(output) {
		['insertCount': output]
    }
}